#ifndef _SCUL_ACTIVETARGET_H_
#define _SCUL_ACTIVETARGET_H_

#include <e32base.h>
#include "Function.h"

namespace scalp
	{
	
	class CActiveTargetConnection;
	
	class CActiveTarget : public CActive
		{
		friend class CActiveTargetConnection;
		private:
		CFunction<void(void)>* iCancelCallback;
		RArray< CFunction<void(void)>* > iRunLCallbackArray;
		CFunction<TInt(TInt)>* iRunErrorCallback;
		
		protected:
		void RunL();
		TInt RunError(TInt aError);
		void DoCancel();
			
		public:
		void SetActive() { CActive::SetActive(); }
		CActiveTarget(CFunction<void(void)>* aCancelCallback = NULL, CFunction<TInt(TInt)>* aRunErrorCallback = NULL, const TPriority& aPriority = EPriorityStandard);
		CActiveTargetConnection* AppendRunConnectionL( CFunction<void(void)>* aCallback);
		CFunction<void(void)>* AppendRunL( CFunction<void(void)>* aCallback);
		void SetCancel( CFunction<void(void)>* aCallback);
		void SetRunError( CFunction<TInt(TInt)>* aCallback);
		virtual ~CActiveTarget();
		};

	class CActiveTargetConnection
	{
	friend class CActiveTarget;
	private:
	CActiveTarget* iActiveTarget;
	CFunction<void(void)>* iCallback;
	CActiveTargetConnection(CActiveTarget* aActiveTarget, CFunction<void(void)>* aCallback);
	public:
	~CActiveTargetConnection();
	};
	
	}

#endif // _SCUL_ACTIVETARGET_H_
